# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=pygobject
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python2-gobject" "${MINGW_PACKAGE_PREFIX}-python3-gobject" "${MINGW_PACKAGE_PREFIX}-pygobject-devel")
pkgver=3.20.1
pkgrel=1
pkgdesc="Allows you to load glade interface files in a program at runtime (mingw-w64)"
arch=(any)
url="http://www.pygtk.org"
license=('LGPL')
makedepends=("${MINGW_PACKAGE_PREFIX}-python2"
             "${MINGW_PACKAGE_PREFIX}-python3"
             "${MINGW_PACKAGE_PREFIX}-gobject-introspection"
             "${MINGW_PACKAGE_PREFIX}-gnome-common")
options=('staticlibs' 'strip')
source=(https://download.gnome.org/sources/pygobject/${pkgver%.*}/${_realname}-${pkgver}.tar.xz)
sha256sums=('3d261005d6fed6a92ac4c25f283792552f7dad865d1b7e0c03c2b84c04dbd745')

prepare() {
  cd "${srcdir}/${_realname}-${pkgver}"
  autoreconf -fi
  #WANT_AUTOMAKE=latest ./autogen.sh
}

build() {
  rm -rf python{2,3}-build devel || true
  mkdir python{2,3}-build devel

  for builddir in python{2,3}-build; do
    #cp -r ${_realname}-${pkgver} ${builddir}
    pushd ${builddir} > /dev/null
      PYTHON=${MINGW_PREFIX}/bin/${builddir%-build} \
      ../${_realname}-${pkgver}/configure \
        --prefix=${MINGW_PREFIX} \
        --build=${MINGW_CHOST} \
        --host=${MINGW_CHOST} \
        --target=${MINGW_CHOST} \
        --disable-silent-rules
      make VERBOSE=1
    popd > /dev/null
  done
}

package_python2-gobject() {
  pkgdesc="Python 2 bindings for GObject2 (mingw-w64)"
  depends=("${MINGW_PACKAGE_PREFIX}-glib2"
           "${MINGW_PACKAGE_PREFIX}-python2-cairo"
           "${MINGW_PACKAGE_PREFIX}-libffi"
           "${MINGW_PACKAGE_PREFIX}-gobject-introspection-runtime"
           "${MINGW_PACKAGE_PREFIX}-pygobject-devel=${pkgver}")

  cd python2-build
  make DESTDIR="${pkgdir}" install
  mv "${pkgdir}${MINGW_PREFIX}"/{include,lib/pkgconfig} "${srcdir}/devel"
}

package_python3-gobject() {
  pkgdesc="Python 3 bindings for GObject2 (mingw-w64)"
  depends=("${MINGW_PACKAGE_PREFIX}-glib2"
           "${MINGW_PACKAGE_PREFIX}-python3-cairo"
           "${MINGW_PACKAGE_PREFIX}-libffi"
           "${MINGW_PACKAGE_PREFIX}-gobject-introspection-runtime"
           "${MINGW_PACKAGE_PREFIX}-pygobject-devel=${pkgver}")

  cd python3-build
  make DESTDIR="${pkgdir}" install

  rm -r "${pkgdir}${MINGW_PREFIX}"/{include,lib/pkgconfig}
}

package_pygobject-devel() {
  pkgdesc="Development files for the pygobject bindings"

  cd "devel"
  mkdir -p "${pkgdir}${MINGW_PREFIX}"/{include,lib}
  mv include "${pkgdir}${MINGW_PREFIX}/"
  mv pkgconfig "${pkgdir}${MINGW_PREFIX}/lib/"
}

package_mingw-w64-i686-pygobject-devel() {
  package_pygobject-devel
}

package_mingw-w64-x86_64-pygobject-devel() {
  package_pygobject-devel
}

package_mingw-w64-i686-python2-gobject() {
  package_python2-gobject
}

package_mingw-w64-i686-python3-gobject() {
  package_python3-gobject
}

package_mingw-w64-x86_64-python2-gobject() {
  package_python2-gobject
}

package_mingw-w64-x86_64-python3-gobject() {
  package_python3-gobject
}
